package com.qgs.waf.redis;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.google.gson.Gson;

public class GenRandomData {
	private static Gson gson = new Gson();

	public static String getRandomIp() {
		int ip_datas[] = new int[4];
		for (int i = 0; i < ip_datas.length; i++) {
			ip_datas[i] = new Random().nextInt(254);
		}
		return ips2ip(ip_datas);
	}

	public static String ips2ip(int ips[]) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < ips.length; i++) {
			sb.append(ips[i]);
			if (i < ips.length - 1) {
				sb.append(".");
			}
		}
		return sb.toString();
	}

	public static String getCity() {
//		String citys[] = new String[] { "Bangkok 曼谷 （首都）", "Buriram武里南", "Lopburi华富里", "Tak达府", "Udonthani乌隆", "Pattaya帕塔亚", "Pyong Yang平壤（首都）", "Huishan惠山", "Kanggye江界", "Sinuiju新义州", "Kaesong 开城" };
		String citys[] = new String[] { "石家庄","保定市","秦皇岛","唐山市","邯郸市","邢台市","沧州市","承德市","廊坊市","衡水市","张家口"};
		return citys[new Random().nextInt(citys.length)];
	}
	public static String getIndustry() {
		String industrys[] = new String[] { "政府", "法院", "税务", "民政", "金融", "其他" };
		return industrys[new Random().nextInt(industrys.length)];
	}
	public static String getProvince() {
//		String provinces[] = new String[] { "浙江", "上海", "江苏", "江西", "河北", "北京" };
		String provinces[] = new String[] { "河北"};
		return provinces[new Random().nextInt(provinces.length)];
	}

	public static String getCountry() {
		String countrys[] = new String[] { "北京", "上海", "香港", "深圳", "广州", "台北", "南京", "大连", "苏州", "青岛", "无锡", "佛山", "重庆", "宁波", "杭州", "成都", "武汉", "澳门", "天津", "沈阳", "厦门", "泉州", "珠海", "东莞", "唐山", "福州", "长沙", "大庆", "常州", "西安", "烟台", "潍坊", "徐州", "中山", "济南", "鄂尔多斯", "哈尔滨", "长春", "包头", "呼和浩特", "绍兴", "江门", "惠州", "新竹", "温州", "高雄", "湛江", "淄博", "秦皇岛", "昆明", "南通", "扬州", "洛阳", "郑州", "乌鲁木齐", "威海", "金华", "芜湖", "南宁", "鞍山", "嘉兴", "东营", "漳州", "株洲", "营口", "台州", "泰州", "台南", "镇江", "马鞍山", "南昌", "日照", "湘潭", "吉林", "德阳", "太原", "绵阳", "兰州", "宜昌", "沧州", "襄阳", "邯郸", "延安", "合肥", "榆林", "桂林", "淮安", "柳州", "岳阳", "克拉玛依", "贵阳", "海口", "喀什", "大同", "锦州", "宜宾", "南阳", "银川", "咸阳", "九江", "日本", "俄罗斯", "韩国", "美国", "英国", "法国", "墨西哥" };
		return countrys[new Random().nextInt(countrys.length)];
	}
	public static String getCS_type() {
		String typs[] = new String[] { "DDOS 端口扫描", "netbios-fs", "http", "smtp", "microsoft-dos" };
		return typs[new Random().nextInt(typs.length)];
	}
	public static String getWebsite() {
		String typs[] = new String[] { "萧山人民政府", "杭州人民法院", "浙江税务局", "上海人民法院","辽宁公安厅","上海海事局"};
		return typs[new Random().nextInt(typs.length)];
	}

	public static List<Map<String, Object>> getData() {
		List<Map<String, Object>> list = getDatas();
		return list;
	}

	public static Map<String, Object> getCS() {
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map<String, Object>> l=getData();
		Map<String, Object> m=l.get(new Random().nextInt(l.size()));
		map.put("ip", getRandomIp());
		map.put("type", getCS_type());
		map.put("city", getCity());
		map.put("country", getCountry());
		map.put("company", m.get("company"));
		map.put("province", m.get("province"));
		map.put("industry", m.get("industry"));
		return map;
	}

	public static int getRandomScore(){
		return new Random().nextInt(5000);
	}
	
	public static String getCSJson() {
		return gson.toJson(getCS());
	}

	public static void main(String[] args) {
		String json;
		for (int i = 0; i < 100; i++) {
			json = gson.toJson(getCS());
			System.out.println(getRandomScore()+"\t"+json);
		}
	}

	public static List<Map<String, Object>> getDatas() {
		List<Map<String, Object>> lists = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("company", "国家电力浙江公司");
		map.put("province", "浙江");
		map.put("industry", "电力");
		lists.add(map);
		Map<String, Object> map1 = new HashMap<String, Object>();
		map1.put("company", "杭州市政府");
		map1.put("province", "浙江");
		map1.put("industry", "政府");
		lists.add(map1);
		Map<String, Object> map2 = new HashMap<String, Object>();
		map2.put("company", "上海市政府");
		map2.put("province", "上海");
		map2.put("industry", "政府");
		lists.add(map);
		Map<String, Object> map3 = new HashMap<String, Object>();
		map3.put("company", "上海电力");
		map3.put("province", "上海");
		map3.put("industry", "电力");
		lists.add(map3);
		Map<String, Object> map4 = new HashMap<String, Object>();
		map4.put("company", "浙江公安厅");
		map4.put("province", "浙江");
		map4.put("industry", "公安");
		lists.add(map4);
		Map<String, Object> map5 = new HashMap<String, Object>();
		map5.put("company", "上海海关");
		map5.put("province", "上海");
		map5.put("industry", "海关");
		lists.add(map5);
		Map<String, Object> map6 = new HashMap<String, Object>();
		map6.put("company", "杭州人民法院");
		map6.put("province", "浙江");
		map6.put("industry", "法院");
		lists.add(map6);
		Map<String, Object> map7 = new HashMap<String, Object>();
		map7.put("company", "宁波人民法院");
		map7.put("province", "浙江");
		map7.put("industry", "法院");
		lists.add(map7);
		Map<String, Object> map8 = new HashMap<String, Object>();
		map8.put("company", "苏州旅游局");
		map8.put("province", "江苏");
		map8.put("industry", "其他");
		lists.add(map7);
		return lists;
	}
}
